package com.leetcode.LC_MED;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public class LC17_2 {
    public List<String> letterCombinations(String digits) {

        ArrayList<String> list = new ArrayList<>();
        if (digits.length() == 0) {
            return list;
        }
        String[] strings = {null, null, "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        dfs(strings, digits, 0, new StringBuilder(), list);
        return list;
    }

    private void dfs(String[] strings, String digits, int index, StringBuilder sb, List<String> list) {
        //剪枝
        if (sb.length() == digits.length()) {
            list.add(sb.toString());
            return;
        }
        //选区节点
        String string = strings[digits.charAt(index) - '0'];
        for (int i = 0; i < string.length(); i++) {
            sb.append(string.charAt(i));
            dfs(strings, digits, index + 1, sb, list);
            sb.deleteCharAt(sb.length() - 1);
        }
    }

    public static void main(String[] args) {
        for (String letterCombination : new LC17_2().letterCombinations("23")) {
            System.out.print(letterCombination + ",");
        }
        UUID uid = null;
        String value = null;
        System.out.println(Objects.toString(uid));
        System.out.println(uid);
        System.out.println(String.format("hhhhh%s", "123"));
        System.out.println(String.format("hhhhh%s", null));
        System.out.println(value);
        System.out.println();
    }
}
